package com.monkeysonnet.b2dFluent;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.physics.box2d.joints.WeldJoint;
import com.badlogic.gdx.physics.box2d.joints.WeldJointDef;

public class WeldJointFactory extends JointFactory<WeldJointFactory>
{
	private static final WeldJointDef _initialDef = new WeldJointDef();
	
	private WeldJointDef _def;
	
	public WeldJointFactory()
	{
		this(false);
	}
	
	WeldJointFactory(boolean managed)
	{
		super(managed);
		_def = new WeldJointDef();
		setDef(_def);
	}
	
	public WeldJointFactory localAnchorA (Vector2 v)
	{
		_def.localAnchorA.set(v);
		return this;
	}
	
	public WeldJointFactory localAnchorA (float x, float y)
	{
		_def.localAnchorA.set(x, y);
		return this;
	}

	public WeldJointFactory referenceAngle(float a)
	{
		_def.referenceAngle = a;
		return this;
	}
	
	public WeldJoint create(World w)
	{
		return (WeldJoint)w.createJoint(_def);
	}
	
	void clear()
	{
		super.clear(_initialDef);
		_def.localAnchorA.set(_initialDef.localAnchorA);
		_def.localAnchorB.set(_initialDef.localAnchorB);
		_def.referenceAngle = _initialDef.referenceAngle;
	}

	@Override
	public void free()
	{
		B2d.free(this);
	}
}
